package org.yellow.backend.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yellow.backend.mapper.appointmentMapper;
import org.yellow.backend.pojo.Appointment;

import java.util.HashMap;

/**
 * @author: hy
 * @create: 2024-01-01
 */
@Service
public class appointmentService {
    @Autowired
    appointmentMapper mapper;

    /**
     * 根据id查询对应的预约情况
     * @param id
     * @return
     */
    public Appointment selectAppointmentById(int id){
        return mapper.selectById(id);
    }

    /**
     * 插入新的预约情况
     * @param appoint
     * @return
     */
    public boolean insertAppointment(Appointment appoint){
        mapper.insert(appoint);
        return true;
    }

    /**
     * 通过患者Id查询对应的医生id
     * @param id
     * @return
     */
    public Long selectByPatientId(int id){
        QueryWrapper<Appointment> wrapper = new QueryWrapper<>();
        wrapper.select("doctor_id").eq("patient_id", id);
        Appointment appointment = mapper.selectOne(wrapper);
        return appointment.getDoctorId();
    }

    /**
     * 根据病人id删除预约信息
     * @param id
     * @return
     */
    public boolean deleteByPatientId(Long id){
        HashMap<String, Object> map = new HashMap<>();
        map.put("patient_id",id);
        mapper.deleteByMap(map);
        return true;
    }


    public void updateStatus(int id) {
        mapper.updateStatusById(id);
    }

    public Long selectIdByPatientId(Long patientId) {
        return mapper.selectIdByPatientId(patientId);
    }
}
